package com.example.campusforumapi.controller;

import com.example.campusforumapi.entity.DepartmentStats;
import com.example.campusforumapi.entity.WeeklyStats;
import com.example.campusforumapi.service.StatsService;
import com.example.campusforumapi.service.UserService;
import com.example.campusforumapi.util.PageResult;
import com.example.campusforumapi.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/stats")
public class StatsController extends BaseController{
    @Autowired
    private StatsService statsService;

//    获取每周每日注册用户数
    @GetMapping("/weeklyRegistrations")
    public Result getWeeklyRegistrations() {
//        try {
            List<WeeklyStats> data = statsService.getWeeklyRegistrations();
            return Result.success(data);
//        } catch (Exception e) {
//            return Result.error( "服务器内部错误");
//        }
    }

//    获取学院人数比例动态数据
        @GetMapping("/departmentUsers")
        public Result getDepartmentUsers() {
        //        try {
            List<DepartmentStats> data = statsService.getDepartmentUsers();
            return Result.success(data);
        //        } catch (Exception e) {
        //            return Result.error( "服务器内部错误");
        //        }
        }

    //    获取学院人数比例动态数据
    @GetMapping("/genderUsers")
    public Result getGenderUsers() {
        //        try {
        List<DepartmentStats> data = statsService.getGenderUsers();
        return Result.success(data);
        //        } catch (Exception e) {
        //            return Result.error( "服务器内部错误");
        //        }
    }

    //    获取文章前七日热度排行前十榜单
    @RequestMapping(value = "/topArticleList", method = RequestMethod.GET)
    public Result topArticleList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize
            ){

        //        查询并封装分页结果集
        PageResult topArticlePage = statsService.getTopArticlePage(page,pageSize);

        return Result.success(topArticlePage);
    }

    //    获取文章前七日热度排行前十榜单
    @RequestMapping(value = "/topActivityList", method = RequestMethod.GET)
    public Result topActivityList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize
    ){

        //        查询并封装分页结果集
        PageResult topActivityPage = statsService.getTopActivityPage(page,pageSize);

        return Result.success(topActivityPage);
    }
    //    获取文章标签占比
    @GetMapping("/articleTags")
    public Result articleTags() {
        //        try {
        List<DepartmentStats> data = statsService.getArticleTags();
        return Result.success(data);
        //        } catch (Exception e) {
        //            return Result.error( "服务器内部错误");
        //        }
    }
    //    获取活动标签占比
    @GetMapping("/activityTags")
    public Result activityTags() {
        //        try {
        List<DepartmentStats> data = statsService.getActivityTags();
        return Result.success(data);
        //        } catch (Exception e) {
        //            return Result.error( "服务器内部错误");
        //        }
    }
}
